package com.jingdianjichi.auth.domain.service.Impl;

import cn.dev33.satoken.secure.SaSecureUtil;
import com.jingdianjichi.auth.common.enums.AuthUserStatusEnum;
import com.jingdianjichi.auth.common.enums.IsDeletedCodeEnum;
import com.jingdianjichi.auth.domain.convent.AuthUserConverter;
import com.jingdianjichi.auth.domain.entity.AuthUserBo;
import com.jingdianjichi.auth.domain.service.AuthUserDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthUser;
import com.jingdianjichi.auth.infra.basic.service.AuthUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AuthUserDomainServiceImpl implements AuthUserDomainService {

    @Resource
    AuthUserService authUserService;
    @Override
    public void add(AuthUserBo authUserBo) {

        AuthUser authUser = AuthUserConverter.INSERT.conventBoToCategory(authUserBo);
         authUser.setPassword(SaSecureUtil.md5BySalt(authUser.getPassword(), "sss"));
        authUser.setStatus(AuthUserStatusEnum.OPEN.getCode());
        authUser.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
        authUserService.insert(authUser);
    }

    @Override
    public Boolean update(AuthUserBo authUserBo) {
        AuthUser authUser = AuthUserConverter.INSERT.conventBoToCategory(authUserBo);

        return authUserService.update(authUser);
    }

    @Override
    public Boolean delect(AuthUserBo authUserBo) {
        AuthUser authUser = AuthUserConverter.INSERT.conventBoToCategory(authUserBo);
        authUser.setStatus(AuthUserStatusEnum.CLOSE.getCode());
        authUser.setIsDeleted(IsDeletedCodeEnum.DELETED.getCode());

        return authUserService.update(authUser);
    }


}
